home *** CD-ROM | disk | FTP | other *** search
- (*----------------------------------------------------------------------*)
- (* Display_Archive_Contents --- Display contents of archive file *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE Display_Archive_Contents( ArcFileName : AnyStr );
-
- (*----------------------------------------------------------------------*)
- (* *)
- (* Procedure: Display_Archive_Contents *)
- (* *)
- (* Purpose: Displays contents of an archive (.ARC file) *)
- (* *)
- (* Calling sequence: *)
- (* *)
- (* Display_Archive_Contents( ArcFileName : AnyStr ); *)
- (* *)
- (* ArcFileName --- name of archive file whose contents *)
- (* are to be listed. *)
- (* *)
- (* Calls: *)
- (* *)
- (* Aside from internal subroutines, these routines are required: *)
- (* *)
- (* Long_To_Real --- convert long (32 bit) INTEGER to real *)
- (* Dir_Convert_Date --- convert DOS packed date to string *)
- (* Dir_Convert_Time --- convert DOS packed time to string *)
- (* Display_File_Info --- display information about a file *)
- (* Open_File --- open a file *)
- (* Close_File --- close a file *)
- (* *)
- (*----------------------------------------------------------------------*)
-
- (*----------------------------------------------------------------------*)
- (* Map of Archive file entry header *)
- (*----------------------------------------------------------------------*)
-
- TYPE
- Archive_Entry_Type = RECORD
- Marker : BYTE (* Flags beginning of entry *);
- Version : BYTE (* Compression method *);
- Filename : ARRAY[1..13] OF CHAR (* file and extension *);
- Size : LongInt (* Compressed size *);
- Date : INTEGER (* Packed date *);
- Time : INTEGER (* Packed time *);
- CRC : INTEGER (* Cyclic Redundancy Check *);
- OLength : LongInt (* Original length *);
- END;
-
- CONST
- Archive_Header_Length = 29 (* Length of an archive header entry *);
- Archive_Marker = 26 (* Marks start of an archive header *);
-
- VAR
- ArcFile : FILE (* Archive file to be read *);
- Archive_Entry : Archive_Entry_Type (* Header for one file in archive *);
- Archive_Pos : REAL (* Current byte offset in archive *);
- Bytes_Read : INTEGER (* # bytes read from archive file *);
- Ierr : INTEGER (* Error flag *);
-
- (*----------------------------------------------------------------------*)
- (* Get_Next_Archive_Entry --- Get next header entry in archive *)
- (*----------------------------------------------------------------------*)
-
- FUNCTION Get_Next_Archive_Entry( VAR ArcEntry : Archive_Entry_Type;
- VAR Error : INTEGER ) : BOOLEAN;
-
- (*----------------------------------------------------------------------*)
- (* *)
- (* Function: Get_Next_Archive_Entry *)
- (* *)
- (* Purpose: Gets header information for next file in archive *)
- (* *)
- (* Calling sequence: *)
- (* *)
- (* OK := Get_Next_Archive_Entry( VAR ArcEntry : *)
- (* Archive_Entry_Type; *)
- (* VAR Error : INTEGER ); *)
- (* *)
- (* ArcEntry --- Header data for next file in archive *)
- (* Error --- Error flag *)
- (* OK --- TRUE if header successfully found, else FALSE *)
- (* *)
- (*----------------------------------------------------------------------*)
-
- BEGIN (* Get_Next_Archive_Entry *)
- (* Assume no error to start *)
- Error := 0;
- (* Except first time, move to *)
- (* next supposed header record in *)
- (* archive. *)
-
- IF ( Archive_Pos <> 0.0 ) THEN
- LongSeek( ArcFile, Archive_Pos );
-
- (* Read in the file header entry. *)
-
- BlockRead( ArcFile, ArcEntry, Archive_Header_Length, Bytes_Read );
- Error := 0;
- (* If wrong size read, or header marker *)
- (* byte is incorrect, report archive *)
- (* format error. *)
-
- IF ( ( Bytes_Read < Archive_Header_Length ) OR
- ( ArcEntry.Marker <> Archive_Marker ) ) THEN
- Error := Format_Error
- ELSE (* Header looks ok -- see if it *)
- (* is the end of file marker. *)
-
- IF ( ArcEntry.Version = 0 ) THEN
- Error := End_Of_File
- ELSE (* Not end of file marker -- get entry data. *)
- WITH ArcEntry DO
- BEGIN
- (* Get position of next archive header *)
-
- Archive_Pos := Archive_Pos + Long_To_Real( Size ) +
- Archive_Header_Length;
-
- (* Adjust for older archives *)
-
- IF ( Version = 1 ) THEN
- BEGIN
- OLength := Size;
- Version := 2;
- Archive_Pos := Archive_Pos - 2.0;
- END;
-
- END;
- (* Report success/failure to calling *)
- (* routine. *)
-
- Get_Next_Archive_Entry := ( Error = 0 );
-
- END (* Get_Next_Archive_Entry *);
-
- (*----------------------------------------------------------------------*)
- (* Display_Archive_Entry --- Display archive header entry *)
- (*----------------------------------------------------------------------*)
-
- PROCEDURE Display_Archive_Entry( Archive_Entry : Archive_Entry_Type );
-
- VAR
- SDate : STRING[10];
- STime : STRING[12];
- I : INTEGER;
- FName : AnyStr;
- RLength : REAL;
-
- BEGIN (* Display_Archive_Entry *)
-
- WITH Archive_Entry DO
- BEGIN
- (* Pick up file name *)
-
- Fname := COPY( FileName, 1, POS( #0 , FileName ) - 1 );
-
- (* Get original file size *)
-
- RLength := Long_To_Real( Olength );
-
- (* Get date and time of creation *)
-
- Dir_Convert_Date( Date , SDate );
- Dir_Convert_Time( Time , STime );
-
- (* Write out file name, length, date, time *)
-
- WRITE( Output_File , Left_Margin_String, ' ' , FName );
-
- FOR I := LENGTH( FName ) TO 13 DO
- WRITE( Output_File , ' ' );
-
- WRITE ( Output_File , RLength:8:0, ' ' );
- WRITE ( Output_File , SDate, ' ' );
- WRITE ( Output_File , STime );
- WRITELN( Output_File );
-
- (* Count lines left on page *)
- IF Do_Printer_Format THEN
- BEGIN
- Lines_Left := Lines_Left - 1;
- IF ( Lines_Left < 1 ) THEN
- Display_Page_Titles;
- END;
-
- END;
-
- END (* Display_Archive_Entry *);
-
- (*----------------------------------------------------------------------*)
-
- BEGIN (* Display_Archive_Contents *)
-
- (* Set left margin spacing *)
-
- Left_Margin_String := Left_Margin_String + DUPL( ' ' , ArcLbr_Indent );
-
- (* Set file title *)
-
- File_Title := Left_Margin_String + ' Archive file: ' + ArcFileName;
-
- (* Display archive file's name *)
- IF Do_Printer_Format THEN
- IF ( Lines_Left < 3 ) THEN
- Display_Page_Titles;
-
- WRITELN( Output_File ) ;
- WRITE ( Output_File , File_Title );
-
- IF Do_Printer_Format THEN
- Lines_Left := Lines_Left - 2;
-
- (* Try opening archive file for processing *)
-
- Open_File( ArcFileName , ArcFile, Archive_Pos, Ierr );
-
- (* Issue error message if open fails *)
- IF ( Ierr <> 0 ) THEN
- BEGIN
- WRITELN( Output_File , DUPL( ' ' , 13 - LENGTH( ArcFileName ) ),
- ' Can''t open archive file ',ArcFileName );
- IF Do_Printer_Format THEN
- BEGIN
- Lines_Left := Lines_Left - 1;
- IF ( Lines_Left < 1 ) THEN
- Display_Page_Titles;
- END;
- EXIT;
- END
- ELSE
- BEGIN
- WRITELN( Output_File );
- WRITELN( Output_File );
- (* Count lines left on page *)
- IF Do_Printer_Format THEN
- BEGIN
- Lines_Left := Lines_Left - 1;
- IF ( Lines_Left < 1 ) THEN
- Display_Page_Titles;
- END;
- END;
- (* Loop over entries in archive file *)
-
- WHILE( Get_Next_Archive_Entry( Archive_Entry , Ierr ) ) DO
- Display_Archive_Entry( Archive_Entry );
-
- (* Close archive file *)
- Close_File( ArcFile );
- (* Restore previous left margin spacing *)
-
- Left_Margin_String := DUPL( ' ' , Left_Margin );
-
- (* No file title *)
- File_Title := '';
-
- END (* Display_Archive_Contents *);